let supportedAPIs: string[] = null

class FBThen
{
    public then(func:Function):FBThen
    {
        return this
    }

    public catch(func:Function):FBThen
    {
        return this
    }
}

export default class FB
{
    public static logEvent(eventName,valueToSum,parameters):any
    {
        console.log("logEvent",eventName)
        if(!FB.IsSupportAPI("logEvent")) return new FBThen()
        return FBInstant.logEvent(eventName,valueToSum,parameters)
    }

    public static onPause(func:Function)
    {
        if(!FB.IsSupportAPI("onPause")) return
        return FBInstant.onPause(func)
    }

    public static canCreateShortcutAsync():any
    {
        if(!FB.IsSupportAPI("canCreateShortcutAsync")) return new FBThen()
        return FBInstant.canCreateShortcutAsync()
    }

    public static createShortcutAsync():any
    {
        if(!FB.IsSupportAPI("createShortcutAsync")) return new FBThen()
        return FBInstant.createShortcutAsync()
    }

    public static createRewardedVideoAd(object: any): any
    {
        if(!FB.IsSupportAPI("createRewardedVideoAd")) return new FBThen()
        return FBInstant.createRewardedVideoAd(object)
    }

    public static shareAsync(object: any)
    {
        if(!FB.IsSupportAPI("shareAsync")) return new FBThen()
        return FBInstant.shareAsync(object)
    }


    public static getLeaderboardAsync(name:string):any
    {
        if(!FB.IsSupportAPI("getLeaderboardAsync")) return new FBThen()
        return FBInstant.getLeaderboardAsync(name)
    }

    public static getEntryPointAsync():any
    {
        if(!FB.IsSupportAPI("getEntryPointAsync")) return new FBThen()
        return FBInstant.getEntryPointAsync()
    }

    public static getEntryPointData():any
    {
        if(!FB.IsSupportAPI("getEntryPointData")) return {}
        return FBInstant.getEntryPointData()
    }

    public static getRewardedVideoAsync(adUnitId:string):any
    {
        if(!FB.IsSupportAPI("getRewardedVideoAsync")) return new FBThen()
        return FBInstant.getRewardedVideoAsync(adUnitId)
    }

    public static getInterstitialAdAsync(adUnitId:string):any
    {
        if(!FB.IsSupportAPI("getInterstitialAdAsync")) return new FBThen()
        return FBInstant.getInterstitialAdAsync(adUnitId)
    }

    public static getSupportedAPIs():string[]
    {
        if(!FB.IsSupportAPI("getSupportedAPIs")) return []
        return FBInstant.getSupportedAPIs()
    }


    //FB是否支持某个API
    public static IsSupportAPI(name:string):boolean
    {
        if(!FB.InFB) return false

        if(!supportedAPIs) supportedAPIs = FBInstant.getSupportedAPIs();
        return supportedAPIs.indexOf(name) !== -1
    }

    public static updateAsync(object:any):any
    {
        if(!FB.IsSupportAPI("updateAsync")) return new FBThen()
        return FBInstant.updateAsync(object)
    }

    public static quit()
    {
        if(!FB.IsSupportAPI("quit")) return
        return FBInstant.quit()
    }

    //当前是否运行在FB环境
    public static get InFB()
    {
        return window["FBInstant"]
    }

}